﻿using EasyCore.Excel;
using System.Data;

namespace EasyCore.ConsoleApp
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Console.WriteLine("Hello, World!");

            DataTable dt = new DataTable();
            dt.Columns.Add("组名");
            dt.Columns.Add("姓名");
            dt.Columns.Add("性别");
            dt.Columns.Add("年龄");
            for (var index = 1; index <= 10; index++) {
                var row = dt.NewRow();
                row["组名"] = "天天向上";
                row["姓名"] = string.Format("测试者{0}",index);
                row["性别"] = index % 2 == 1 ? "男" : "女";
                row["年龄"] = 32 + index;
                dt.Rows.Add(row);
            }  
            ExcelMapper excelMapper = new ExcelMapper();
            //var sdMapper = excelMapper.CreateDataTableSheetMapper("DataTable");
            //sdMapper.Put(dt);


            //var sdMapper2 = excelMapper.CreateDataTableSheetMapper("DataTable2");
            //sdMapper2.Map(m =>
            //{
            //    m.ColumnName = "UserName";
            //    m.FieldName = "姓名";
            //});
            //sdMapper2.Map(m =>
            //{
            //    m.ColumnName = "Sex";
            //    m.FieldName = "性别";
            //    m.FormatColumnVal = (index, row) =>
            //    {
            //        return "性别";
            //    };
            //});
            //sdMapper2.Map(m =>
            //{
            //    m.ColumnName = "年龄"; 
            //});
            //sdMapper2.Put(dt);


            var sdMapper3 = excelMapper.CreateDataTableSheetMapper("DataTable3");
            sdMapper3.Map(m =>
            {
                m.ColumnName = "序号";
                m.ColumnType = ColumnType.MainIndex;
            });
            sdMapper3.Map(m =>
            {
                m.ColumnName = "组名";
                m.FieldName = "组名";
                m.ColumnType = ColumnType.MainGroupKey;
            });
            sdMapper3.Map(m => {
                m.ColumnName = "基本信息";
                m.AddChildrenColumn(m =>
                {
                    m.ColumnName = "子序号";
                    m.ColumnType = ColumnType.SubIndex;
                });
                m.AddChildrenColumn(m =>
                {
                    m.ColumnName = "UserName";
                    m.FieldName = "姓名";
                    m.ColumnType = ColumnType.SubData;
                });
                m.AddChildrenColumn(m =>
                {
                    m.ColumnName = "Sex";
                    m.FieldName = "性别";
                    m.ColumnType = ColumnType.SubData;
                    m.FormatColumnVal = (index, row) =>
                    {
                        return "性别";
                    };
                });
                m.AddChildrenColumn(m =>
                {
                    m.ColumnName = "年龄";
                    m.ColumnType = ColumnType.SubData;
                    m.IsHide = true;
                });

            });
            sdMapper3.Put(dt);

            string filePath = string.Format(@"C:\Users\Administrator\Desktop\Test\{0}.xlsx", "abc");
            excelMapper.Save(filePath);







        }
    }
}